2. 線形空間と線形写像
code: vec2d.py
from numpy import array
import matplotlib.pyplot as plt
arrows = [(o, x + y, 'b'), (o, x, 'r'), (x, y, 'g'),
(o, y, 'g'), (y, x, 'r')]
for p, v, c in arrows:
plt.quiver(p0, p1, v0, v1, color=c, units='xy', scale=1)
plt.axis('scaled'), plt.xlim(0, 5), plt.ylim(0, 5), plt.show()
https://gyazo.com/69620cb24986d53a4b0f6d0ecaab5c88
code: vec3d.py
from vpython import vec, arrow, mag
o = vec(0, 0, 0)
x, y, z = vec(1, 0, 0), vec(0, 1, 0), vec(0, 0, 1)
arrows = [(o, x + y), (x, y + z), (o, x + y + z), (o, x), (y, x),
(z, x), (y + z, x), (o, y), (x, y), (z, y), (x + z, y),
(o, z), (x, z), (y, z), (x + y, z)]
for p, v in arrows:
arrow(pos=p, axis=v, color=v, shaftwidth=mag(v) / 50)
https://gyazo.com/b593db758d033459dd118c1db26428d9
code: func.py
from numpy import pi, sin, cos, linspace
import matplotlib.pyplot as plt
f = lambda x: x**2 + x + 1
g = lambda x: 3 * sin(x) + 4 * cos(x)
x = linspace(-pi, pi, 101)
plt.plot(x, y)
plt.show()
https://gyazo.com/716b889128717f2c98d9f28cedadde37https://gyazo.com/5df241427116834b74472a81e9a37a8d
code: comp.py
from numpy import exp, pi, linspace
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
f = lambda n, x: exp(1j * n * x)
x = linspace(0, 2 * pi, 1001)
ax = Axes3D(plt.figure())
for n in range(-2, 3):
ax.plot(x, f(n, x).real, f(n, x).imag)
plt.show()
https://gyazo.com/a893e20bbd0e93692fdc3e07c10483a9
code: sound2.py
import scipy.io.wavfile as wav
import numpy as np
import matplotlib.pyplot as plt
rate, Data = wav.read('mono.wav')
print(rate, Data.shape)
t = len(Data) / rate
dt = 1 / rate
print(t, dt)
x = np.arange(0, t, dt)
y = Data / 32768
if len(Data.shape) == 1:
plt.plot(x, y)
plt.xlim(0, t), plt.ylim(-1, 1), plt.show()
elif len(Data.shape) == 2:
fig, ax = plt.subplots(2)
for i in range(2):
axi.set_xlim(0, t), axi.set_ylim(-1, 1) plt.show()
https://gyazo.com/383a8bdf2c10d069c3283879dda07046https://gyazo.com/e27ac97c83b06cfa0724ef2b6ec654f7
code: chord.py
from numpy import arange, pi, sin
import scipy.io.wavfile as wav
import matplotlib.pyplot as plt
xmax, rate = 2, 22050
x = arange(0, xmax, 1 / rate)
def f(hz):
A = f(440.000000) # ラ
B = f(493.883301) # シ
C = f(523.251131) # ド
D = f(587.329536) # レ
E = f(659.255114) # ミ
F = f(698.456463) # ファ
G = f(783.990872) # ソ
Data = (CEG * 32768).astype('int16')
wav.write('CEG.wav', rate, Data)
for y in [C0, E0, G0, CEG]: plt.plot(x, y)
plt.xlim(1, 1.01), plt.show()
https://gyazo.com/1b412ddd691dd474da4713883396c0a1